<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<div class="form-horizontal">
    <div class="form-group">
        <label class="control-label col-md-2">用户名</label>
        <div class="col-md-4">
            <input type="text" id="account" name="account" class="form-control" placeholder="请输入用户名"/>
        </div>
    </div>
    <div class="form-group">
        <label class="control-label col-md-2">密码</label>
        <div class="col-md-4">
            <input type="password" id="password" name="password" class="form-control"
                   placeholder="请输入密码"/>
        </div>
    </div>
    <div class="form-group">
        <label class="control-label col-md-2">再输一次</label>
        <div class="col-md-4">
            <input type="password" id="confirmPassword" name="confirmPassword" class="form-control"
                   placeholder="请输入密码"/>
        </div>
    </div>
    <div class="form-group">
        <label class="control-label col-md-2">用户昵称</label>
        <div class="col-md-4">
            <input type="text" id="realname" name="realname" class="form-control"
                   placeholder="请输入用户昵称"/>
        </div>
    </div>
    <div class="form-group">
        <label class="control-label col-md-2">商户</label>
        <div class="col-md-4">
            <label>
                <select id="merchant_id" name="merchantId" class="form-control"></select>
            </label>
        </div>
    </div>
    <div class="form-group">
        <label class="control-label col-md-2">性别</label>
        <div class="col-md-4">
            <label>
                <select name="sex" id="sex" class="form-control">
                    <option value="0">请选择</option>
                    <option value="1">男</option>
                    <option value="2">女</option>
                </select>
            </label>
        </div>
    </div>
    <div class="form-group">
        <label class="control-label col-md-2">手机号</label>
        <div class="col-md-4">
            <input type="text" id="phone" name="phone" class="form-control" placeholder="请输入手机号">
        </div>
    </div>
    <div class="form-group">
        <label class="control-label col-md-2">邮箱</label>
        <div class="col-md-4">
            <input type="text" id="email" name="email" class="form-control" placeholder="请输入邮箱">
        </div>
    </div>
</div>

<div class="form-group">
    <div class="col-md-offset-2 col-md-10">
        <button type="submit" class="btn btn-primary">
            <i class="fa fa-floppy-o"></i> 保存
        </button>
    </div>
</div>
<script type="text/javascript">
    $(document).ready(function () {
        /**
         * 商户列表
         */
        $.ajax({
            url: "/system/wwdx_merchant/list/json",
            dataType: "json",
            success: function (data) {
                var merchantId = document.getElementById("merchant_id");
                $.each(data.data, function (index, obj) {
                    //item.options.length = 0;清除所有option值
                    merchantId[0] = new Option("请选择", "", true, true);
                    merchantId[index + 1] = new Option(obj.merchant_name, obj.id);
                });
            },
            error: function (data) {
                alert(data.message);
            }
        });
        
        $("#form1").bootstrapValidator({
            feedbackIcons: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {
                account: {
                    validators: {
                        notEmpty: {
                            message: '不能为空'
                        },
                        stringLength: {
                            min: 6,
                            max: 18,
                            message: '长度必须在6到18位之间'
                        },
                        regexp: {
                            regexp: /^[a-zA-Z0-9_]+$/,
                            message: '数字字母下划线'
                        },
                        remote: {
                            type: 'POST',
                            url: '/system/upms_user/validate',
                            message: '用户名已存在',
                            delay: 3000
                        },
                        different: {
                            field: 'password,confirmPassword',
                            message: '不能与密码相同'
                        }
                    }
                },
                password: {
                    validators: {
                        notEmpty: {
                            message: '不能为空'
                        },
                        stringLength: {
                            min: 6,
                            max: 18,
                            message: '长度必须在6到18位之间'
                        },
                        regexp: {
                            regexp: /^[a-zA-Z0-9_]+$/,
                            message: '数字字母下划线'
                        },
                        identical: {
                            field: 'confirmPassword',
                            message: '两次密码输入不一致'
                        },
                        different: {
                            field: 'account',
                            message: '不能与账号相同'
                        }
                    }
                },
                confirmPassword: {
                    validators: {
                        notEmpty: {
                            message: '不能为空'
                        },
                        stringLength: {
                            min: 6,
                            max: 18,
                            message: '长度必须在6到18位之间'
                        },
                        regexp: {
                            regexp: /^[a-zA-Z0-9_]+$/,
                            message: '数字字母下划线'
                        },
                        identical: {
                            field: 'password',
                            message: '两次密码输入不一致'
                        },
                        different: {
                            field: 'account',
                            message: '不能与账号相同'
                        }
                    }
                },
                sex: {
                    validators: {
                        regexp: {
                            regexp: /^[1-2]*$/,
                            message: '必须选择其中的一个'
                        }
                    }
                },
                realname: {
                    validators: {
                        notEmpty: {
                            message: '不能为空'
                        }
                    }
                },
                phone: {
                    validators: {
                        notEmpty: {
                            message: '不能为空'
                        },
                        regexp: {
                            regexp: /^(((13[0-9]{1})|(15[0-9]{1})|(17[0-9]{1})|(18[0-9]{1}))+\d{8})$/,
                            message: '手机号格式不正确'
                        }
                    }
                },
                email: {
                    validators: {
                        notEmpty: {
                            message: '不能为空'
                        },
                        emailAddress: {
                            message: '邮箱格式不正确'
                        }
                    }
                }
            }
        });
    });
</script>